import type { UploadUserFile } from "element-plus";

export interface GetSpuListApiParams {
  page: number;
  limit: number;
  category3Id: number;
}

/*
{
  "records": [
      {
          "id": 3421,
          "spuName": "11111111111111111111111111",
          "description": "1111111111111111111",
          "category3Id": 61,
          "tmId": 22,
          "spuSaleAttrList": null,
          "spuImageList": null
      }
  ],
  "total": 12,
  "size": 1,
  "current": 1,
  "searchCount": true,
  "pages": 12
}
*/
export interface SpuItem {
  id: number;
  spuName: string;
  description: string;
  category3Id: number;
  tmId: number;
  // spuSaleAttrList: null;
  // spuImageList: null;
}

export type SpuList = SpuItem[];

export interface GetSpuListApiResponse {
  records: SpuList;
  total: number;
}

// 基础销售属性
export interface BaseSaleAttrItem {
  id: number;
  name: string;
}

export type BaseSaleAttrList = BaseSaleAttrItem[];

export interface SpuImageItem {
  id?: number;
  imgName: string;
  imgUrl: string;
}

export type SpuImageList = SpuImageItem[];

export interface SpuSaleAttrValueItem {
  baseSaleAttrId: number;
  id?: number;
  saleAttrValueName: string;
}

export type SpuSaleAttrValueList = SpuSaleAttrValueItem[];

export interface SpuSaleAttrItem {
  baseSaleAttrId: number;
  id?: number;
  saleAttrName: string;
  spuSaleAttrValueList: SpuSaleAttrValueList;
}

export type SpuSaleAttrList = SpuSaleAttrItem[];

export interface SaveOrUpdateSpuApiParams {
  category3Id: number;
  id?: number;
  spuName: string;
  tmId: number;
  description: string;
  spuImageList: SpuImageList;
  spuSaleAttrList: SpuSaleAttrList;
}

/*
  添加SPU
    {
      "spuName": "string",
      "tmId": 0
      "description": "string",
      "spuImageList": [
        {
          "imgName": "string",
          "imgUrl": "string",
        }
      ],
      "spuSaleAttrList": [
        {
          "baseSaleAttrId": 0,
          "saleAttrName": "string",
          "spuSaleAttrValueList": [
            {
              "baseSaleAttrId": 0,
              "saleAttrValueName": "string",
            }
          ]
        }
      ],
      "category3Id": 0,
    }
  更新SPU
     {
      "id": 0,
      "category3Id": 0,
      "spuName": "string",
      "tmId": 0
      "description": "string",
      "spuImageList": [
        {
          "id": 0,
          "imgName": "string",
          "imgUrl": "string",
          "spuId": 0
        }
      ],
      "spuSaleAttrList": [
        {
          "baseSaleAttrId": 0,
          "id": 0,
          "saleAttrName": "string",
          "spuId": 0,
          "spuSaleAttrValueList": [
            {
              "baseSaleAttrId": 0,
              "id": 0,
              "isChecked": "string",
              "saleAttrName": "string",
              "saleAttrValueName": "string",
              "spuId": 0
            }
          ]
        }
      ],
    }

  组件需要
    {
      "spuName": string,
      "tmId": undefined | number
      "description": string,
      "spuImageList": UploadUserFile[],
      "spuSaleAttrList": [
        {
          "baseSaleAttrId": 0,
          "id": 0,
          "saleAttrName": "string",
          "spuId": 0,
          "spuSaleAttrValueList": [
            {
              "baseSaleAttrId": 0,
              "id": 0,
              "isChecked": "string",
              "saleAttrName": "string",
              "saleAttrValueName": "string",
              "spuId": 0
            }
          ],
          isEdit: boolean
        }
      ],
    }
*/

export interface SaveSpuSaleAttrItem extends SpuSaleAttrItem {
  isEdit: boolean;
}

export type SaveSpuSaleAttrList = SaveSpuSaleAttrItem[];

export interface SpuFormData
  extends Pick<SaveOrUpdateSpuApiParams, "id" | "spuName" | "description"> {
  tmId: undefined | number;
  spuImageList: UploadUserFile[];
  spuSaleAttrList: SaveSpuSaleAttrList;
}
